<template>
    <div>
        <div class="icon">
            <i class="icon-icon_wancheng1"></i>
        </div>
        <p class="success">签约成功</p>

        <div class="btn" @click="backHome">返回首页</div>
    </div>
</template>

<script setup lang="js">
import { onLoad } from "@dcloudio/uni-app";
import {ref, reactive } from "vue"
import { orderRentSign, queryOrderContract } from '@/api/order'
import Interact from '@/utils/interact';


const orderNo = ref("")
const contractStatus = ref("")
let orderRentSignSuccess = false

onLoad((options) => {
    orderNo.value = options.orderNo
    queryOrderContract({
        orderNo: orderNo.value,
    }).then(res =>{
        contractStatus.value = res.data.contractStatus
        console.log(contractStatus.value);
        if(contractStatus.value == '01') {
            doOrderRentSign()
        }
    })
})


const doOrderRentSign = () => {
    orderRentSign({
        orderNo: orderNo.value,
    }, {
        noErrorToast: true
    }).then(res => {
        orderRentSignSuccess = true
        Interact.modal({
            title: '提示',
            message: '签约成功',
        }).then(() => {
            backHome()
        })
    }, err => {
        if(err.code == -3) {
            // 已签约
            orderRentSignSuccess = true
        } else {
            Interact.toast(err.msg)
        }
    })
}
const backHome = async () => {
    if(!orderRentSignSuccess) {
        doOrderRentSign()
    } else {
        uni.switchTab({
            url: '/pages/index',
        })
    }
}
</script>
<style lang="scss" scoped>
.icon{
    display: flex;
    justify-content: center;
    padding-top: 200rpx;
    .icon-icon_wancheng1{
        font-size: 150rpx;
        color: #149e08;
        margin-top: 200rpx;
        margin: 0 auto;
        display: block;
    }
}

.success{
    font-size: 40rpx;
    color: #149e08;
    text-align: center;
    margin-top: 30rpx;
    padding-right: 30rpx;
}
.btn{
    width: 600rpx;
    height: 100rpx;
    background: #d1921c;
    border-radius: 10rpx;
    font-size: 36rpx;
    color: #fff;
    text-align: center;
    line-height: 100rpx;
    margin: 0 auto;
    margin-top: 100rpx;
}

</style>
